// pages/cai/cai.js

let animationShowHeight = 0;
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    zhe:false,
    tiao:false,
    guize: false
  },
  showguize:function(e){
    // 显示遮罩层
  
    this.setData({
      zhe: true,
      guize:true
    })
  },
  hideguize:function(){
    console.log('123')
    var that = this;
    that.setData({
      zhe: false,
      guize: false
    })
  },

  start_tiao:function(){
    console.log(this.data.dati)
    if(this.data.dati == 1){
      wx.showToast({
        title: '您没有答题机会了',
        icon:"none"
      })
      return false
    } else if (this.data.dati == 0){
      wx.navigateTo({
        url: '../checkpoint/checkpoint?id=1',
      })
    }else{
      
    }
    
    
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (app.globalData.userInfo == "") {
      wx.getSetting({
        success: function (res) {
          if (res.authSetting['scope.userInfo']) {
            wx.getUserInfo({
              success: function (res) {
                //从数据库获取用户信息
                console.log(res)
                app.globalData.userInfo = res.userInfo;
                that.setData({
                  userInfo: res.userInfo
                })

              }
            });
          } else {
            wx.navigateTo({
              url: '../login/login',
            })
          }
        }
      })
    }
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    if (app.globalData.opid == "") {
     
      wx.navigateTo({
        url: '../login/login',
      })
    }
    console.log('用户信息')
    console.log(app.globalData.userInfo)
    wx.hideLoading()
    that.setData({
      userInfo: app.globalData.userInfo
    })


    wx.request({
      url: app.globalData.url+'jingcai.php?Action=tongjidati',
      data:{
        openid:app.globalData.opid
      },
      success:function(res){
        console.log(res)
        console.log(app.globalData.opid)
       that.setData({
         dati:res.data.dati,
         fenxiang:res.data.fenxiang,
         userInfo:app.globalData.userInfo
       })
        
      }
    })
    wx.request({
      url: app.globalData.url +'ziyu.php?Action=article&id=59',
      success:function(res){
        that.setData({
          rule:res.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.globalData.url + 'jingcai.php?Action=tongjidati',
      data: {
        openid: app.globalData.opid
      },
      success: function (res) {
        console.log(res)
        that.setData({
          dati: res.data.dati,
          fenxiang: res.data.fenxiang,
          userInfo: app.globalData.userInfo
        })

      }
    })
    if (!app.globalData.opid) {
      wx.hideLoading()
      wx.navigateTo({
        url: '../login/login',
      })
    }
    if (app.globalData.userInfo == "") {
      wx.getSetting({
        success: function (res) {
          if (res.authSetting['scope.userInfo']) {
            wx.getUserInfo({
              success: function (res) {
                //从数据库获取用户信息
                console.log(res)
                app.globalData.userInfo = res.userInfo;
                that.setData({
                  userInfo: res.userInfo
                })

              }
            });
          }
        }
      })
    }
  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    console.log(res)
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '向你发起智商挑战，不服来试试，赢了奖品归你！',
      path: 'pages/share/share?id='+app.globalData.opid
    }
  }
})